from flask import Flask, request, render_template, redirect

app = Flask(__name__)

user_data = {
    1: {'name': '张三', 'age': 23, 'gender': '男'},
    2: {'name': '李四', 'age': 18, 'gender': '男'},
    3: {'name': '王五', 'age': 35, 'gender': '女'},
}


@app.route('/index')
def index():
    return render_template('index.html', user=user_data)


@app.route('/login', methods=['GET', 'POST'], endpoint='login')
def login():
    if request.method == 'GET':
        return render_template('login.html')
    else:
        user = request.form.get("user")
        pwd = request.form.get("pwd")
        if user == "root" and pwd == "123":
            return redirect('/index')
        return render_template('login.html')


if __name__ == '__main__':
    app.run(debug=True, host="0.0.0.0", port=80)
